﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using LeadMaster.DAL;
using LeadMaster.Models;
using System.Web.Security;
using System.Data;
using LeadMaster.ViewModels;
using System.Web.Providers.Entities;

namespace LeadMaster.Helpers
{
  public static class SiteValues
  {
    private static DunsmoreContext db = new DunsmoreContext();

    public static ViewModelPerson FetchIntroInfo()
    {
      Guid currentUser = (Guid)Membership.GetUser().ProviderUserKey;
      string userName=db.Users.Where(m => m.UserID==currentUser).FirstOrDefault().UserName;
      ViewModelPerson viewModel=new ViewModelPerson();
      List<CallCentres> listcc = db.CallCentres.Where(m => m.UserName == userName).ToList();
      CallCentres cc = db.CallCentres
                        .Where(m => m.UserName==userName)
                        .FirstOrDefault();
      if (cc != null)
      {
        switch (cc.Category)
        {
          case "I":
            viewModel.WelcomeMessage = "- Agent - Welcome back " + cc.Contact1;
            break;
          case "N":
            viewModel.WelcomeMessage = "- Installer - Welcome back " + cc.Contact1;
            string ownerCat = db.CallCentres.Find(cc.OwnedBy).Category;
            if (ownerCat=="C")
            {
              viewModel.Admin = true; // belongs to Love Your Earth so an Admin Installer account
            }
            break;
          case "E":
            viewModel.WelcomeMessage = "- Engineer - Welcome back " + cc.Contact1;
            break;
          case "C":
            viewModel.WelcomeMessage = "- Love Your Earth - Welcome back " + cc.Contact1;
            break;
          case "D":
            viewModel.WelcomeMessage = "- DEA/GDA - Welcome back " + cc.Contact1;
            break;
          case "O":
            viewModel.WelcomeMessage = "- Dunsmore Marketing - Welcome back " + cc.Contact1;
            break;
          default:
            break;
        }
        viewModel.TC = cc.ConfirmedTC;
        viewModel.PersonType = cc.Category;
        viewModel.Person = cc;
        viewModel.Person.ConfirmedTC = cc.ConfirmedTC;
        if (cc.OwnedBy == null && cc.Category!="I")
        {
          viewModel.Admin = true;  
        }
        
      }
        return viewModel;
    }
  }
}